package com.amsp.oa.oademo.controller;

import com.amsp.oa.oademo.entity.InspectionRecord;
import com.amsp.oa.oademo.service.InspectionRecordService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@Api(tags = "文件资料稽查表接口")
@RestController
@RequestMapping("/api/inspection")
public class InspectionRecordController {

    @Autowired
    private InspectionRecordService inspectionRecordService;

    @ApiOperation("分页查询稽查记录")
    @GetMapping("/page")
    public IPage<InspectionRecord> getPage(
            @ApiParam("页码") @RequestParam(defaultValue = "1") Integer pageNum,
            @ApiParam("每页数量") @RequestParam(defaultValue = "10") Integer pageSize,
            @ApiParam("关键字") @RequestParam(required = false) String keyword) {
        return inspectionRecordService.getPage(pageNum, pageSize, keyword);
    }

    @ApiOperation("获取稽查记录详情")
    @GetMapping("/{id}")
    public InspectionRecord getById(@PathVariable Long id) {
        return inspectionRecordService.getById(id);
    }

    @ApiOperation("保存稽查记录")
    @PostMapping("/save")
    public boolean save(@RequestBody List<InspectionRecord> records) {
        return inspectionRecordService.saveOrUpdateBatch(records);
    }

    @ApiOperation("删除稽查记录")
    @DeleteMapping("/{id}")
    public boolean removeById(@PathVariable Long id) {
        return inspectionRecordService.removeById(id);
    }

    @ApiOperation("批量删除稽查记录")
    @DeleteMapping("/batch")
    public boolean removeBatchByIds(@RequestBody List<Long> ids) {
        return inspectionRecordService.removeByIds(ids);
    }
}